package com.cz.cloud.user.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.cz.cloud.client.OrderClient;
import com.cz.cloud.client.dto.OrderDTO;
import com.cz.cloud.client.dto.UserDTO;
import com.cz.cloud.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private OrderClient orderClient;

    @Value("${node}")
    private String node;

    @GetMapping("/{id}")
    public UserDTO getUser(@PathVariable("id") Long id) {
        UserDTO userDTO = BeanUtil.copyProperties(userMapper.selectById(id), UserDTO.class);
        List<OrderDTO> orderDTOList = orderClient.getOrdersByUserId(id);
        userDTO.setNode(node);
        userDTO.setOrders(orderDTOList);
        return userDTO;
    }
}
